<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Student extends Base{
    //PC学员风采
    public function allstudent(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.page"))){
            $page=input("param.page");
        }else{
            return json(['code' => 503, 'msg' => '当前分页数']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $student=Db::name('student')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->limit(4*($page-1),4)->select();
            if($student){
                for ($i=0; $i <count($student) ; $i++) { 
                    $student[$i]['times']=date('Y-m-d',$student[$i]['uptime']);
                }
                return json(['code' => 200, 'msg' => '成功！','data'=>$student]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pallstudent(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.page"))){
            $page=input("param.page");
        }else{
            return json(['code' => 503, 'msg' => '当前分页数']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $student=Db::name('student')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->limit(4*($page-1),4)->select();
                if($student){
                    for ($i=0; $i <count($student) ; $i++) { 
                        $student[$i]['times']=date('Y-m-d',$student[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$student]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $student=Db::name('student')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->limit(4*($page-1),4)->select();
                if($student){
                    for ($i=0; $i <count($student) ; $i++) { 
                        $student[$i]['times']=date('Y-m-d',$student[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$student]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //学员风采详情
    public function studentdetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $detail=Db::name('student')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
            if($detail){
                $detail['times']=date('Y-m-d',$detail['time']);
                return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
}